using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Ideopuzzle
{
    public class AudioManager
    {
        private SoundEffectInstance click, gingle, boom, flip;
        private float pitch, pan;        

        public AudioManager(Game game)
        {
            click = game.Content.Load<SoundEffect>("Audio/click").CreateInstance();
            gingle = game.Content.Load<SoundEffect>("Audio/backgroundgingle").CreateInstance();
            boom = game.Content.Load<SoundEffect>("Audio/boom").CreateInstance();
            flip = game.Content.Load<SoundEffect>("Audio/switch").CreateInstance();

            pitch = 0.0f;
            pan = 0.0f;
        }

        public void PlaySwitch()
        {
            flip.Volume = Options.Volume;
            flip.Pitch = pitch;
            flip.Pan = pan;

            if (Options.Sound)
                flip.Play();
        }

        public void PlayClick()
        {
            click.Volume = Options.Volume;
            click.Pan = pan;
            click.Pitch = pitch;

            if (Options.Sound)
                click.Play();
        }

        public void PlayGingle()
        {
            gingle.Volume = Options.Volume;
            gingle.Pan = pan;
            gingle.Pitch = pitch;

            if (Options.Sound && Options.PlayBackgroundMusic && !(MediaPlayer.State == MediaState.Playing))
            {
                if (!gingle.IsLooped) gingle.IsLooped = true;
                gingle.Play();
            }
        }

        public void StopGingle()
        {
            if (Options.Sound && Options.PlayBackgroundMusic && gingle.State == SoundState.Playing)
                gingle.Stop();
        }

        public void PlayExplosion()
        {
            boom.Volume = Options.Volume;
            boom.Pitch = pitch;
            boom.Pan = pan;

            if (Options.Sound)
                boom.Play();
        }
    }
}
